import { request } from "@/http/axios"
import {timeFormats} from "../project/projectType/projectTypeApi.js"
import * as XLSX from "xlsx";
export function cementDelects(Ids) {
  return request({
    url: 'cement/cementDelects',
    method: 'post',
    data: {
      Ids: Ids
    }
  })
}

export function cementPage(form) {
  return request({
    url: 'cement/cementPage',
    method: 'post',
    data: form
  })
}
export function cementAdd(form) {
  return request({
    url: 'cement/cementAdd',
    method: 'post',
    data: form
  })
}
export function cementEdit(form) {
  return request({
    url: 'cement/cementEdit',
    method: 'post',
    data: form
  })
}

export function cementTitle(title) {
  const url = `cement/cementTitle?title=${encodeURIComponent(title)}`;
  return request({
    url: url,
    method: 'get',
  })
}

export function announCement(title) {
  const url = `cement/announCement`;
  return request({
    url: url,
    method: 'get',
  })
}

//导出公告内容
export function exportNotifcationExcel(data){
  let tableData = [
    ['序号', "公告标题", "公告内容", "公告类型", "公告封面", "公告附件","创建人","创建时间","公告状态"]//导出表头
  ] // 表格表头
  data.forEach((item, index) => {
    let rowData = []
    //导出内容的字段
    rowData = [
      index + 1,
      item.title,
      item.content,
      item.cementType,
      item.imgUrl,
      item.file,
      item.userName,
      item.createTime,
      item.statuss,
    ]
    tableData.push(rowData)
  })
  let workSheet = XLSX.utils.aoa_to_sheet(tableData);
  let bookNew = XLSX.utils.book_new();
  XLSX.utils.book_append_sheet(bookNew, workSheet, '作品名称') // 工作簿名称
  let name = '公告导出数据' + timeFormats() + '.xlsx'
  XLSX.writeFile(bookNew, name) // 保存的文件名
}
